<?php
/**
 * This file contains compatibility global functions aliases, to prevent some
 * PHP system errors.
 */


// clone() function for PHP 4
if (version_compare(phpversion(), '5.0') < 0) {
	eval('
		    function clone($object)
		    {
		    	return $object;
		    }
	    ');
}

if (!function_exists('strptime')) {
// strptime() function for windows systems. Get from http://forum.academ.org/index.php?showtopic=187558
	function strptime ( $strdate, $format ) {
		$plop = array( 's'=>'tm_sec', 'i'=>'tm_min', 'H'=>'tm_hour',
		'd'=>'tm_mday', 'm'=>'tm_mon', 'Y'=>'tm_year');

		$regexp = preg_quote($format, '/');
		$regexp = str_replace(
			array('%d','%m','%Y','%H','%i','%s'),
			array('(\d{2})','(\d{2})','(\d{4})','(\d{2})','(\d{2})','(\d{2})'),
			$regexp);
		if (preg_match('/^' . $regexp.'$/', $strdate,$m)) {
			$result = array('tm_sec'=>0,'tm_min'=>0,'tm_hour'=>0,'tm_mday'=>0,'tm_mon'=>0,'tm_year'=>0,'tm_wday'=>0,'tm_yday'=>0,'unparsed'=>'');
			preg_match_all('/%(\w)/',$format,$patt);
			foreach($patt[1] as $k=>$v) {
				if(!isset($plop[$v])) {
					continue;
				}
				$result[$plop[$v]] = intval($m[$k+1]);
				if($plop[$v] == 'tm_mon') {
					$result[$plop[$v]] -= 1;
				}
			}
			$result['tm_year'] -= 1900;
			return $result;
		}
		else {
			return false;
		}
	}
}


if (!function_exists('parse_ini_file')) { //function from http://phpclub.ru/talk/threads/%D0%9A%D0%BB%D0%B0%D1%81%D1%81-%D0%B4%D0%BB%D1%8F-%D1%80%D0%B0%D0%B1%D0%BE%D1%82%D1%8B-%D1%81-ini-%D1%84%D0%B0%D0%B9%D0%BB%D0%B0%D0%BC%D0%B8.70506/
    function parse_ini_file ( $filename, $process_sections = false) {
        $ini = file( $filename );
        if ( count( $ini ) == 0 ) { return array(); }
        $sections = array();
        $values = array();
        $globals = array();
        $out = array();
        $i = 0;
        foreach( $ini as $line ){
            $line = trim( $line );
            // Comments
            if ( $line == '' || $line{0} == ';' ) { continue; }
            // Sections
            if ( $line{0} == '[' ) {
                $sections[] = substr( $line, 1, -1 );
                $i++;
                continue;
            }
            // Key-value pair
            list( $key, $value ) = explode( '=', $line, 2 );
            $key = trim( $key );
            $value = trim( $value );
            if ( $i == 0 ) {
                // Array values
                if ( substr( $line, -1, 2 ) == '[]' ) {
                    $globals[ $key ][] = $value;
                } else {
                    $globals[ $key ] = $value;
                }
            } else {
                // Array values
                if ( substr( $line, -1, 2 ) == '[]' ) {
                    $values[ $i - 1 ][ $key ][] = $value;
                } else {
                    $values[ $i - 1 ][ $key ] = $value;
                }
            }
        }
        for( $j=0; $j<$i; $j++ ) {
            $result[ $sections[ $j ] ] = $values[ $j ];
        }
        if ($process_sections == false){
            $without_sections = array();
            foreach ($result as $value) {
                foreach($value as $key => $res){
                    $without_sections[$key] = $res;
                }
            }
            $out = $without_sections;
        } else {$out = $result;}

        return $out + $globals;
    }
}

if (!isset($_SERVER['QUERY_STRING'])) {
    $_SERVER['QUERY_STRING'] = '';
}
